﻿<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
    style="padding: 20px 30px 0 0;">

    <script type='text/html' template>
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}"/>
    </script>
    <div class='layui-form-item'>
        <label class='layui-form-label'>会员编号<label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Code' value='{{ d.params.Code || '' }}' lay-verify='required' placeholder='会员编号' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>会员姓名<label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Name' value='{{ d.params.Name || '' }}' lay-verify='required' placeholder='会员姓名' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>手机号<label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='Phone' value='{{ d.params.Phone || '' }}' lay-verify='required' placeholder='手机号' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>会员等级序号<label style="color: red">*</label></label>
        <div class='layui-input-inline'>
            <!-- <input type='text' name='Level' value='{{ d.params.Level || '' }}' lay-verify='required|number' placeholder='会员等级' autocomplete='off' class='layui-input'> -->
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"Level");'>
                    <select name='Level' id='Level' xm-select="Level" xm-select-radio="" lxm-select-search="" >
                        <option value='' {{ d.params.IsOpen_Sel == '' ? 'selected' : '' }}>无需会员等级限制</option>
                    </select>
                </script>

        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>有效期</label>
        <div class='layui-input-block'>
            <script type='text/html' template lay-done='layui.data.datedone(d.params);'>
                <input type='text' name='VailDate' readonly='readonly' id='VailDate' value='{{ d.params.VailDate || '' }}' lay-verify='datetime' placeholder='yyyy-MM-dd HH:mm:ss' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>


    <div class='layui-form-item'>
        <label class='layui-form-label'><span id="sourcespan">所属店铺</span><span style="color:red">*</span></label>
        <div class='layui-input-block'>
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"Store");'>
                <select name="select1" id="select1" xm-select="select1" xm-select-radio="" lay-verify='required' xm-select-search xm-select-skin="default">
                    <option value=""></option>
                </select>
                <input type="hidden" name="Store" id="Store" value='{{ d.params.Store || '' }}'>
            </script>
        </div>
    </div>



    <div class='layui-form-item'>
        <label class='layui-form-label'>备注</label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                <input type='text' name='RMK' value='{{ d.params.RMK || '' }}'  placeholder='备注' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>

<script type="text/javascript">
    layui.use(['form', 'admin', 'upload', 'laydate'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
        var $ = layui.$;
    });

    layui.data.getSelSource = function (d, sourceName) {
        layui.use(['admin', 'form', 'formSelects', 'laydate'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            var formSelects = layui.formSelects;
            var laydate = layui.laydate;


            if (sourceName == "Level") {

                formSelects.config('Level', {
                    keyName: 'LevelStr',            //自定义返回数据中name的key, 默认 name
                    keyVal: 'Level',            //自定义返回数据中value的key, 默认 value
                });
                admin.req({
                    url: layui.setter.APIUrl + '/shop/Goods_memberpriceMgr/getLevels', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res) {
                        layui.formSelects.data('Level',
                            'local',
                            {
                                arr: res.Data, //要把自己的这个节点去掉
                                linkeage: false,
                                linkageWidth: 140
                            });

                        if (d.Level) {
                            layui.formSelects.value('Level', [d.Level]);
                        }


                        formSelects.on('Level', function (id, vals, val, isAdd, isDisabled) {
                            if (isAdd == true) {
                                if (val.value == "4") {
                                    laydate.render({
                                        elem: '#VailDate'
                                        , value: '2099-12-31 23:59:59'
                                        , isInitValue: true
                                    });
                                } else if (val.value == "1" || val.value == "2" || val.value == "3") {
                                    var date = new Date();
                                    var year = date.getFullYear();
                                    var timestr = year + '-12-31 23:59:59'
                                    laydate.render({
                                        elem: '#VailDate'
                                        , value: timestr
                                        , isInitValue: true
                                    });
                                } else {
                                    $("#VailDate").val('');
                                }
                            } else {

                                $("#VailDate").val('');
                            }
                        });
                    }
                });
            }

            if (sourceName == 'Store') {

                formSelects.config('select1', {
                    keyName: 'title',            //自定义返回数据中name的key, 默认 name
                    keyVal: 'id',            //自定义返回数据中value的key, 默认 value
                    keyChildren: 'children',    //联动多选自定义children
                });

                admin.req({
                    url: layui.setter.APIUrl + '/shop/storeMgr/customerQueryChildren2', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res) {
                        layui.formSelects.data('select1', 'local', {
                            arr: res.Data,
                            linkage: true,
                            linkageWidth: 120
                        });
                        var selID = d.Store;
                        if (selID != "" && selID != undefined) {
                            admin.req({
                                url: layui.setter.APIUrl + '/shop/storeMgr/GetModel?key=' + selID, //实际使用请改成服务端真实接口
                                type: 'post',
                                done: function (res) {
                                    //如果有需要默认值的小伙伴请使用formSelects.value
                                    formSelects.value('select1', [res.Data.Area + "/" + selID]);
                                }
                            });
                        }
                    }
                });

                formSelects.on('select1', function (id, vals, val, isAdd, isDisabled) {
                    if (isAdd == true) {
                        if (val.value.indexOf("/") > 0) {  //多级选择时,第一级无法选中
                            var value = val.value.split('/')[val.value.split('/').length - 1];
                            $("#Store").val(value);  //实际选中效果为多个ID组合 ‘id1/id2/id3’,取最后一个
                        } else {
                            isAdd = false;
                            return false;
                        }
                    } else {
                        $("#Store").val("");
                    }
                });
            }


        });
    }


    layui.data.setUpload = function (d) {
        layui.use(['upload', 'admin'], function () {
            var $ = layui.$,
                upload = layui.upload,
                admin = layui.admin;
            var formSelects = layui.formSelects;

        });
    }


    layui.data.datedone = function (d) {
        layui.use(['laydate'], function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#VailDate'
                , type: 'datetime'
                , calendar: true
            });
            laydate.val = d.VailDate;

        });
    }   
</script>